window.addEventListener('load', function() {
    var app = new Vue({
        el: '#player',
        data: {
            query: '',
            musicList: [],
            musicUrl: '',
            musicCover: '',
            hotComments: [],
            isPlaying: false,
            mvUrl: '',
            isShow: false
        },
        methods: {
            // 搜索音乐
            searchMusic: function() {
                var that = this;
                axios.get('https://autumnfish.cn/search?keywords=' + this.query)
                    .then(function(response) {
                        console.log(response);
                        // console.log(response.data.result.songs);
                        that.musicList = response.data.result.songs;
                    }, function(err) {})
            },
            // 播放音乐
            playMusic: function(musicId) {
                var that = this;
                axios.get('https://autumnfish.cn/song/url?id=' + musicId)
                    .then(function(response) {
                        // console.log(response);
                        // console.log(response.data.data[0].url);
                        that.musicUrl = response.data.data[0].url;
                    }, function(err) {})
                    // 获取音乐封面
                axios.get('https://autumnfish.cn/song/detail?ids=' + musicId)
                    .then(function(response) {
                        // console.log(response.data.songs[0].al.picUrl);
                        that.musicCover = response.data.songs[0].al.picUrl;
                    }, function(err) {})
                    // 获取音乐评论
                axios.get('https://autumnfish.cn/comment/hot?type=0&id=' + musicId)
                    .then(function(response) {
                        // console.log(response);
                        console.log(response.data.hotComments);
                        that.hotComments = response.data.hotComments;
                    }, function(err) {})
            },
            // 播放和暂停
            play: function() {
                this.isPlaying = true;
            },
            pause: function() {
                this.isPlaying = false;
            },
            // 播放mv
            playMV: function(mvid) {
                var that = this;
                axios.get('https://autumnfish.cn/mv/url?id=' + mvid)
                    .then(function(response) {
                        console.log(response.data.data.url);
                        that.isShow = true;
                        that.mvUrl = response.data.data.url;
                    }, function(err) {})
            },
            hide: function() {
                this.isShow = false;
            }
        }
    })
})